import java.lang.reflect.Array;
import java.util.Arrays;

public class Leet59 {
    public static void main(String[] args) {
        Leet59 l = new Leet59();
        System.out.println(Arrays.deepToString(l.generateMatrix(1)));
    }
    public int[][] generateMatrix(int n) {

        int[][] re = new int[n][n];
        int state = 0;
        int x = 0;
        int y = 0;
        int i = 1;
        if(n==1){
            re[0][0] = 1;
            return re;
        }
        if (n==2){
            re[0][0] = 1;
            re[0][1] = 2;
            re[1][1] = 3;
            re[1][0] = 4;
            return re;
        }
        while(true){
            if(x!=n-1&&x!=0&&y!=n-1&&y!=0){
                if (re[x+1][y]!=0&&re[x-1][y]!=0&&re[x][y+1]!=0&&re[x][y-1]!=0){
                    re[x][y] = i;
                    break;
                }
            }
            if(state==0){
                re[x][y] = i;
                i++;
                y++;
                if (y==n-1){
                    state=1;
                    continue;
                }
                if (re[x][y+1]!=0){
                    state=1;
                    continue;
                }

            }
            if(state==1){
                re[x][y] = i;
                i++;
                x++;
                if (x==n-1){
                    state=2;
                    continue;
                }
                if (re[x+1][y]!=0){
                    state=2;
                    continue;
                }
            }
            if(state==2){
                re[x][y] = i;
                i++;
                y--;
                if (y==0){
                    state=3;
                    continue;
                }
                if (re[x][y-1]!=0){
                    state=3;
                    continue;
                }
            }
            if(state==3){
                re[x][y] = i;
                i++;
                x--;
                if (x==0){
                    state=0;
                    continue;
                }
                if (re[x-1][y]!=0){
                    state=0;
                }

            }

        }
        return re;
    }
}
